package org.gtd4j.aspects;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class Gtd4JLoggingAspect {

	private static Logger logger = Logger.getLogger(Gtd4JLoggingAspect.class);
	
	@Pointcut("within(org.gtd4j..*)")
	public void allGtdPackages() {}
	
	/**
	 * Generic trace logging before all gtd4j methods
	 * @param joinPoint
	 */
	@Before("org.gtd4j.aspects.Gtd4JLoggingAspect.allGtdPackages()")
	public void beforeTraceLog(JoinPoint joinPoint) {
		if( logger.isTraceEnabled() ) {
			logger.trace("entering method " + joinPoint.getSignature());
		}
	}
	
	@After("org.gtd4j.aspects.Gtd4JLoggingAspect.allGtdPackages()")
	public void afterTraceLog(JoinPoint joinPoint) {
		if( logger.isTraceEnabled() ) {
			logger.trace("exited method " + joinPoint.getSignature());
		}		
	}
}
